﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Data;
using System.Windows.Documents;
using System.Windows.Input;
using System.Windows.Media;
using System.Windows.Media.Imaging;
using System.Windows.Shapes;

namespace Deployment.Data.UI.Dialogs.Environment
{
    /// <summary>
    /// Interaction logic for CloneEnvironmentDialog.xaml
    /// </summary>
    public partial class CloneEnvironmentDialog : Window
    {
        
        private ObservableSortedList<Data.Environment.Environment> _environmentsList;


        public CloneEnvironmentDialog(Data.Environment.Environment environmentToClone, ObservableSortedList<Data.Environment.Environment> environmentList)
        {
            InitializeComponent();
            if (environmentToClone == null)
                throw new ArgumentNullException("environmnet");
            this.DataContext = environmentToClone;
            _environmentsList = environmentList;
        }

        public string NewName
        {
            get { return txt_newEnvironmentName.Text; }
        }

        private void okButton_Click(object sender, RoutedEventArgs e)
        {
            foreach (Data.Environment.Environment env in _environmentsList)
            {
                if (string.Equals(env.Name, txt_newEnvironmentName.Text, StringComparison.CurrentCultureIgnoreCase))
                {
                    MessageBox.Show(this, string.Format("An Environment with the name '{0}' already exists in the Environment list.", txt_newEnvironmentName.Text),
                        "Duplicate Environment", MessageBoxButton.OK, MessageBoxImage.Error);
                    return;
                }
            }
            DialogResult = true;
        }
    }
}
